<template>
  <el-row>
    <el-col :span="24">
      <el-card>
        <el-form ref="searchForm" class="el-form-col search-form" :model="search">
          <el-row :gutter="15">
            <el-col :lg="4" :md="6">
              <el-form-item prop="orderNo" style="position: relative">
                <el-input v-model="search.orderNo" type="textarea" :rows="4" clearable placeholder="关联订单号  (支持多单查询，用英文逗号分隔)"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="outWarehouseNo" style="position: relative">
                <el-input v-model="search.outWarehouseNo" type="textarea" :rows="4" clearable placeholder="出库单号  (支持多单查询，用英文逗号分隔)"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="consigneName">
                <el-input v-model="search.consigneName" placeholder="客户姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6" class="hidden-lg-only hidden-xl-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="8">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button type="info" plain @click="isOpen = !isOpen">{{ isOpen ? '收起' : '展开' }}</el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button @click="resetFields" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="consignePhone">
                <el-input v-model="search.consignePhone" placeholder="客户电话"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="owner">
                <el-input v-model="search.owner" placeholder="商家名称"></el-input>
              </el-form-item></el-col>
            <el-col :lg="4" :md="6" class="hidden-md-only hidden-sm-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="8">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button type="info" plain @click="isOpen = !isOpen">{{ isOpen ? '收起' : '展开' }}</el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button @click="resetFields" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="orderType">
                <el-select v-model="search.orderType" placeholder="关联单类型">
                  <el-option v-for="item in orderTypeArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="outType">
                <el-select v-model="search.outType" placeholder="仓储类型">
                  <el-option v-for="item in tempArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item  prop="distributionStartTime">
                <el-date-picker type="date"
                                placeholder="分配时间：开始"
                                v-model="search.distributionStartTime"
                                value-format="yyyy-MM-dd"
                                style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="distributionEndTime">
                <el-date-picker type="date"
                                placeholder="分配时间：结束"
                                v-model="search.distributionEndTime"
                                value-format="yyyy-MM-dd"
                                style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <div v-show="isOpen">
              <el-col :lg="4" :md="6" v-if="state == 4">
                <el-form-item prop="confirmStartTime">
                  <el-date-picker type="date"
                                  placeholder="确认时间:开始"
                                  v-model="search.confirmStartTime"
                                  value-format="yyyy-MM-dd"
                                  style="width: 100%;"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :lg="4" :md="6" v-if="state == 4">
                <el-form-item prop="confirmStartTime">
                  <el-date-picker type="date"
                                  placeholder="确认时间:开始"
                                  v-model="search.confirmStartTime"
                                  value-format="yyyy-MM-dd"
                                  style="width: 100%;"></el-date-picker>
                </el-form-item>
              </el-col>
            </div>
          </el-row>
        </el-form>
      </el-card>
    </el-col>
    <el-col :span="24">
      <BasicTable
        ref="BasicTable"
        url="/ms-warehouse-order/outWarehose/findOutWarehouseList"
        :tabs="tabs"
        :columns="columns">
        <template slot="preColumn">
          <el-table-column prop="orderNo" fixed="left" width="155px" align="center" label="关联单号">
            <template slot-scope="scope">
              <a href="javascript:;" class="blue-color" @click="showOrder(scope.row)">{{ scope.row.orderNo }}</a>
            </template>
          </el-table-column>
          <el-table-column prop="orderNo" fixed="left" width="170px" align="center" label="出库单号">
            <template slot-scope="scope">
              <a href="javascript:;" class="blue-color" @click="showDetail(scope.row, state)">{{ scope.row.outWarehouseNo }}</a>
            </template>
          </el-table-column>
        </template>
        <template slot="column">
          <el-table-column fixed="right" width="100px" align="center" label="操作" v-if="state == 3">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showDetail(scope.row, state)"
              >
                确认出库
              </el-button>
            </template>
          </el-table-column>
          <el-table-column fixed="right" width="100px" align="center" label="操作" v-if="state == 4">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showDetail(scope.row, state)"
              >
                详情
              </el-button>
            </template>
          </el-table-column>
        </template>
      </BasicTable>
    </el-col>
  </el-row>
</template>
<script>
import {filterDataBaseDictionary, unixTimestampFilter} from '@/filters'
// import {copy, dotData} from '@/utils'
import {copy} from '@/utils'
import {getAllWarehouse, getSubDictListOfParentCode} from '@/utils/selectOptions'
export default {
  name: 'outputWarehouseConfirmIndex',
  data() {
    const that = this
    let columns = [
      {
        label: '客户姓名',
        width: '80px',
        data: 'consigneName'
      },
      {
        label: '客户电话',
        width: '100px',
        data: 'consignePhone'
      },
      {
        label: '关联订单类型',
        data: 'orderType',
        width: '120px',
        render(data, full) {
          return filterDataBaseDictionary(data)
        }
      },
      {
        label: '出库仓',
        data: 'outWarehouseName',
        render(data, full) {
          return filterDataBaseDictionary(data)
        }
      },
      {
        label: '仓储类型',
        data: 'outTypeCode',
        width: '100px',
        render(data, full) {
          return filterDataBaseDictionary(data)
        }
      },
      {
        label: '商家名称',
        data: 'owner'
      },
      {
        label: '总体积',
        width: '82px',
        data: 'totalVolume'
      },
      {
        label: '总包件',
        width: '82px',
        data: '',
        render(data, full) {
          if (that.state === '3') {
            return full.totalPlanPackage
          } else {
            return full.totalPackage
          }
        }
      },
      {
        label: '总重量',
        width: '80px',
        data: 'totalWeight'
      }
      // {
      //   label: '录单员',
      //   data: 'founderUserName'
      // },
      // {
      //   label: '录单时间',
      //   width: '134px',
      //   data: 'foundDate',
      //   render(data, full) {
      //     return unixTimestampFilter(data)
      //   }
      // },
      // {
      //   label: '提交完成时间',
      //   width: '134px',
      //   data: 'pickingDate',
      //   render(data, full) {
      //     return unixTimestampFilter(data)
      //   }
      // }
    ]
    let oneColumns = copy(columns, true)
    oneColumns.splice(oneColumns.length, 0, {
      label: '分配人',
      data: 'distributionUserName'
    }, {
      label: '分配时间',
      width: '134px',
      data: 'distributionDate',
      render(data, full) {
        return unixTimestampFilter(data)
      }
    })
    let secondColumns = copy(columns, true)
    secondColumns.splice(secondColumns.length, 0, {
      label: '确认人',
      data: 'confirmUserName'
    }, {
      label: '确认时间',
      width: '134px',
      data: 'confirmDate',
      render(data, full) {
        return unixTimestampFilter(data)
      }
    })
    return {
      warehouseIdArr: [], // 入库仓
      state: 3,
      isOpen: false,
      visible: false,
      searchLoading: false,
      search: {
        outType: '',
        orderType: '',
        outWarehouseNo: '',
        outWarehouseName: '',
        owner: '',
        confirmUserName: '',
        distributionUserName: '',
        distributionStartTime: '',
        distributionEndTime: '',
        founderUserName: '',
        founderStartTime: '',
        founderEndTime: '',
        pickingStartTime: '',
        pickingEndTime: '',
        confirmStartTime: '',
        confirmEndTime: '',
        orderNo: '',
        consigneName: '',
        consignePhone: ''
      },
      orderTypeArr: [], // 关联订单类型
      tempArr: [], // 仓储类型
      mark: 0,
      columns,
      tabs: [
        {
          label: '待确认',
          columns: oneColumns,
          callback: (params) => {
            params.orderState = 'confirm'
            that.state = '3'
          }
        },
        {
          label: '已出库',
          callback: (params) => {
            params.orderState = 'outbound'
            that.state = '4'
          },
          columns: secondColumns
        }
      ],
      typeArr: [],
      item: {}
    }
  },
  created() {
    // 仓储类型：通用字典接口查
    getSubDictListOfParentCode('CARGOSOURCETYPE').then(arr => {
      if (Array.isArray(arr)) {
        this.tempArr = arr
      }
    })
    // 关联订单类型：通用字典接口查
    getSubDictListOfParentCode('STORAGEORDERTYPE').then(arr => {
      if (Array.isArray(arr)) {
        this.orderTypeArr = arr
      }
    })
    // 入库仓
    getAllWarehouse().then(arr => {
      this.warehouseIdArr = arr
    })
  },
  methods: {
    // 搜索
    searchFunc(search) {
      const basicTable = this.$refs.BasicTable
      if (basicTable) {
        let params = copy(search)
        this.searchLoading = true
        basicTable.search(params).finally(_ => {
          this.searchLoading = false
        })
      }
    },
    // 重置表单
    resetFields() {
      const searchForm = this.$refs.searchForm
      if (searchForm) {
        searchForm.resetFields()
      }
    },
    // 表格刷新
    refresh() {
      this.searchFunc(this.search)
    },
    showOrder(data) {
      console.log('跳转到入库单详情')
      this.$router.push({path: '/ss-oms/outputWarehouse/warehousing-order/show/' + data.id})
    },
    // 跳转详情
    showDetail(data, state) {
      this.$router.push({path: '/ss-oms/outputWarehouse/warehouse-confirm/show/' + data.id + '/?state=' + state})
    }
  }
}
</script>
